home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d17 / proff.arc / PXLEX.C < prev    next >
C/C++ Source or Header  |  1988-02-17  |  4KB  |  188 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <ctype.h>
  4.  
  5. /* translation table for control chars */
  6.  
  7. char c_ctrl[] = { 
  8.         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  9.         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  10.         0,  0,  0,  0,  0,  0,  0,  0,
  11.         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  12.         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  13.         0,  0,  0,  0,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
  14.         10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
  15.         23, 25, 26, 27, 28, 29, 30, 31, 0,  1,  2,  3,  4,  5,
  16.         6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  17.         20, 21, 22, 23, 24, 25, 26, 0,  0,  0,  0,  0
  18.         };
  19.  
  20. /*
  21.  * getval - evaluate optional numeric argument
  22.  *
  23.  * increments i
  24.  */
  25. int
  26. getval(buf,i,argtyp)
  27. char buf[];
  28. int *i;
  29. int *argtyp;
  30. {
  31.     int j,k;
  32.  
  33.     j = *i;
  34.     k = *argtyp;
  35.  
  36.     skipbl(buf, &j);
  37.     k = buf[j];
  38.     if (k == '+' || k == '-')
  39.         j++;
  40.     *i = j;
  41.     *argtyp = k;
  42.     return(ctoi(buf,i));
  43. }
  44.  
  45. /*
  46.  * getarg - get the next argument from the buffer
  47.  *
  48.  * return values:      -1 - no argument
  49.  *            n - number of chars in argument
  50.  *
  51.  * also handles quoted ("..") strings. If a quote is wanted
  52.  * in the string, use "" or \". quotes are stripped.
  53.  *
  54.  * argument delimiters: blank, tab or comma (,).
  55.  *
  56.  * increments i
  57.  *
  58.  */
  59. int
  60. getarg(buf,i,arg)
  61. char buf[];
  62. int *i;
  63. char arg[];
  64. {
  65.     int j,k;
  66.     register char ch;
  67.  
  68.     j = *i;
  69.  
  70.     k = -1;
  71.     skipbl(buf,&j);
  72.     if (buf[j] != '\0') {
  73.         k = 0;
  74.         if (buf[j] == '\"') {
  75.             j++;
  76.             while (buf[j] != '\0') {
  77.                 if (buf[j] == '\"') {
  78.                     if (buf[j+1] == '\"') {
  79.                         arg[k++] = '\"';
  80.                         j += 2;
  81.                     }
  82.                     else
  83.                         break;
  84.                 }
  85.                 arg[k++] = buf[j++];
  86.             }
  87.             arg[k] = '\0';
  88.             j++;            /* skip the quote */
  89.             /* peek next char */
  90.             if (isalnum(buf[j]))
  91.                 error("improper argument list.");
  92.             j++;            /* skip the delimeter */
  93.         }
  94.         else {
  95.             ch = buf[j];
  96.             while (ch != ' '&& 
  97.                 ch != '\t'     && 
  98.                 ch != ','     &&
  99.                 ch != '\r'     && 
  100.                 ch != '\n'     && 
  101.                 ch != '\0') {
  102.                 arg[k++] = buf[j++];
  103.                 ch = buf[j];
  104.             }
  105.             arg[k] = '\0';
  106.             if (ch != '\0')    /* if non-null delimiter, skip */
  107.                 j++;
  108.         }
  109.         *i = j;
  110.     }
  111.     return(k);
  112. }
  113.  
  114. /*
  115.  * getpstr - get a special string to print out
  116.  *
  117.  */
  118. getpstr(buf,out)
  119. register char *buf;
  120. register char *out;
  121. {
  122.     register int i;
  123.     register char c, cc;
  124.     register char *num;
  125.     char numbuf[9];
  126.  
  127.     while(*buf != '\n' && *buf != '\0') {
  128.         c = *buf;
  129.         switch(c) {
  130.         case ' ':
  131.         case '\t':
  132.             while (*buf == ' ' || *buf == '\t')
  133.                 buf++;    /* skip blanks */
  134.             break;
  135.         case '\\':
  136.             if (*(buf+1) != '\0') {
  137.                 *out++ = *(buf+1);
  138.                 buf += 2;
  139.             }
  140.             else
  141.                 buf++;
  142.             break;
  143.         case '^':
  144.             if ((cc = c_ctrl[*(buf+1)]) != 0)
  145.                 *out++ = cc;
  146.             buf += 2;
  147.             break;
  148.         case '\"':
  149.             buf++;    /* skip the quote */
  150.             while (*buf != '\0') {
  151.                 if (*buf != '\"')
  152.                     *out++ = *buf++;
  153.                 else if (*(buf+1) == '\"') {
  154.                         *out++ = '\"';
  155.                         buf += 2;
  156.                 }
  157.                 else
  158.                     break;
  159.             }
  160.             buf++;    /* skip the quote */
  161.             break;
  162.         case '0':
  163.         case '1':
  164.         case '2':
  165.         case '3':
  166.         case '4':
  167.         case '5':
  168.         case '6':
  169.         case '7':
  170.         case '8':
  171.         case '9':
  172.             num = numbuf;
  173.             while (isdigit(*buf))
  174.                 *num++ = *buf++;
  175.             *num = '\0';
  176.             if ((i = atoi(numbuf)) > 256)
  177.                 error("non-ascii char value in write string.");
  178.             else if (i > 0)        /* do not output null */
  179.                 *out++ = (char) i;
  180.             break;
  181.         default:
  182.             *out++ = *buf++;
  183.         }
  184.     }
  185.     *out = '\0';
  186. }
  187.  
  188.